//
//  TestViewController.m
//  Test2122
//
//  Created by wangbo-ms on 13-1-6.
//  Copyright (c) 2013年 wangbo-ms. All rights reserved.
//

#define IS_SUPPORT_CAEMITTERLAYER             NSClassFromString(@"CAEmit1terLayer")?YES:NO

#import "TestViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface TestViewController (){
    UIView *view1;
    NSArray *_arr;
}

@end

@implementation TestViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    NSLog(@"viewDidLoad");
    
//    if (IS_SUPPORT_CAEMITTERLAYER) {
//        NSLog(@"yesyes");
//    } else {
//        NSLog(@"nono");
//    }
//    
    view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    [view1 setBackgroundColor:[UIColor greenColor]];
    [self.view addSubview:view1];
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
    [view1 addGestureRecognizer:pan];
    [pan release];
    
    //[view1 setClipsToBounds:YES];
//
//    
//    //创建一个平移手势对象，该对象可以调用handelPan：方法
//    UIPanGestureRecognizer *panGes = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handelPan:)];
//    [view1 addGestureRecognizer:panGes];
//    [panGes release];
    
    
    //NSLog(@"%d",self.view.subviews.count);
    
//    _arr = [[[NSArray alloc]initWithObjects:@"许嵩",@"周杰伦",@"梁静茹",@"许飞",@"凤凰传奇",@"阿杜",@"方大同",@"林俊杰",@"胡夏",@"邱永传", nil] retain];
//    
//    
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//    [btn setFrame:CGRectMake(0, 0, 200, 50)];
//    [self.view addSubview:btn];
//    [btn setTitle:@"add" forState:UIControlStateNormal];
//    [btn addTarget:self action:@selector(btnTapped) forControlEvents:UIControlEventTouchUpInside];
    
    

    
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"ccc");
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"bbb");
}

- (void)pan:(UIGestureRecognizer *)gest {
    //NSLog(@"aaa");
}

- (void)btnTapped {
    
    
    UIPickerView *_pView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-160, 320, 160)];
    [_pView setShowsSelectionIndicator:YES];
    [self.view addSubview:_pView];
    [_pView release];
    [_pView setDelegate:self];
    [_pView setDataSource:self];
    
    CATransition *animation = [CATransition  animation];
    animation.delegate = self;
    animation.duration = 0.5;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromTop;
    
    [self.view setAlpha:1];
    [_pView.layer addAnimation:animation forKey:@"CustomActionSheetView"];

    
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return [_arr count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [_arr objectAtIndex:row];
}


-(void)handelPan:(UIPanGestureRecognizer*)gestureRecognizer{
    //获取平移手势对象在self.view的位置点，并将这个点作为self.aView的center,这样就实现了拖动的效果
    CGPoint curPoint = [gestureRecognizer translationInView:self.view];
    //NSLog(@"%d",[gestureRecognizer state]);
    //[view1 setCenter:curPoint];
    
    [gestureRecognizer setTranslation:CGPointMake(0, 0) inView:self.view];
    
    NSLog(@"xx:%f",curPoint.y);
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
